<?php

namespace App\Http\Controllers;

use App\Http\Controllers\BaseController;
use App\Models\EveryModel;
use App\Repositories\EveryRepository;
use App\Repositories\MoneyLogRepository;
use Illuminate\Http\Request;
use App\Models\MoneyLogModel;

class EveryController extends BaseController
{
    /**
     * @param Request $request
     * @param MoneyLogRepository $moneyRepository
     * @return \Illuminate\Http\JsonResponse
     */
    public function list (Request $request, EveryRepository $everyRepository)
    {
        $params = $request->all();
        $list = @$everyRepository->getList($params);
        return $this->success($list);
    }


    public function getEveryDetail (Request $request) {
        $id = $request->input('id');
        $money = @EveryModel::query()->find($id);
        return $this->success($money);
    }

    /**
     * @param Request $request
     * @param MoneyLogRepository $moneyRepository
     * @return \Illuminate\Http\JsonResponse
     */
    public function save (Request $request, EveryRepository $everyRepository)
    {
        $allParams = $request->all();
        $rst = @$everyRepository->save($allParams);
        if ($rst) {
            return $this->success([]);
        }
        return $this->error(405, '保存失败，请稍后再试');
    }
}
